﻿@model CustomerReportsSearchModel

<div class="panel-group">
    <div class="panel panel-default">
        <div class="panel-body">
            <div class="form-group">
                <div class="col-md-3">
                    <nop-label asp-for="BestCustomersByNumberOfOrders.StartDate"/>
                </div>
                <div class="col-md-9">
                    <nop-editor asp-for="BestCustomersByNumberOfOrders.StartDate"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-3">
                    <nop-label asp-for="BestCustomersByNumberOfOrders.EndDate"/>
                </div>
                <div class="col-md-9">
                    <nop-editor asp-for="BestCustomersByNumberOfOrders.EndDate"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-3">
                    <nop-label asp-for="BestCustomersByNumberOfOrders.OrderStatusId"/>
                </div>
                <div class="col-md-9">
                    <nop-select asp-for="BestCustomersByNumberOfOrders.OrderStatusId" asp-items="Model.BestCustomersByNumberOfOrders.AvailableOrderStatuses"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-3">
                    <nop-label asp-for="BestCustomersByNumberOfOrders.PaymentStatusId"/>
                </div>
                <div class="col-md-9">
                    <nop-select asp-for="BestCustomersByNumberOfOrders.PaymentStatusId" asp-items="Model.BestCustomersByNumberOfOrders.AvailablePaymentStatuses"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-3">
                    <nop-label asp-for="BestCustomersByNumberOfOrders.ShippingStatusId"/>
                </div>
                <div class="col-md-9">
                    <nop-select asp-for="BestCustomersByNumberOfOrders.ShippingStatusId" asp-items="Model.BestCustomersByNumberOfOrders.AvailableShippingStatuses"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-9 col-md-offset-3">
                    <button type="button" id="search-best-customers-numberoforders-grid" class="btn btn-primary btn-search">
                        <i class="fa fa-line-chart"></i>
                        @T("Admin.Reports.Customers.RunReport")
                    </button>
                </div>
            </div>
        </div>
    </div>

    <div class="panel panel-default">
        <div class="panel-body">
            <div id="best-customers-numberoforders-grid"></div>

            <script>
                $(document).ready(function() {
                    $("#best-customers-numberoforders-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@Html.Raw(Url.Action("ReportBestCustomersByNumberOfOrdersList", "Report"))",
                                    type: "POST",
                                    dataType: "json",
                                    data: function() {
                                        var data = {
                                            OrderBy : 2,
                                            StartDate: $('#@Html.IdFor(model => model.BestCustomersByNumberOfOrders.StartDate)').val(),
                                            EndDate: $('#@Html.IdFor(model => model.BestCustomersByNumberOfOrders.EndDate)').val(),
                                            OrderStatusId: $('#@Html.IdFor(model => model.BestCustomersByNumberOfOrders.OrderStatusId)').val(),
                                            PaymentStatusId: $('#@Html.IdFor(model => model.BestCustomersByNumberOfOrders.PaymentStatusId)').val(),
                                            ShippingStatusId: $('#@Html.IdFor(model => model.BestCustomersByNumberOfOrders.ShippingStatusId)').val()
                                        };
                                        addAntiForgeryToken(data);
                                        return data;
                                    }
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors"
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            pageSize: @(Model.BestCustomersByNumberOfOrders.PageSize),
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            pageSizes: [@(Model.BestCustomersByNumberOfOrders.AvailablePageSizes)],
                            @await Html.PartialAsync("_GridPagerMessages")
                        },
                        editable: {
                            confirmation: "@T("Admin.Common.DeleteConfirmation")",
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [
                            {
                                field: "CustomerName",
                                title: "@T("Admin.Reports.Customers.BestBy.Fields.Customer")"
                            }, {
                                field: "OrderTotal",
                                title: "@T("Admin.Reports.Customers.BestBy.Fields.OrderTotal")"
                            }, {
                                field: "OrderCount",
                                title: "@T("Admin.Reports.Customers.BestBy.Fields.OrderCount")"
                            }, {
                                field: "Id",
                                title: "@T("Admin.Common.View")",
                                width: 100,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                                template: '<a class="btn btn-default" href="@Url.Content("~/Admin/Customer/Edit/")#=CustomerId#"><i class="fa fa-eye"></i>@T("Admin.Common.View")</a>'
                            }
                        ]
                    });
                });
            </script>

            <script>
                $(document).ready(function() {
                    $('#search-best-customers-numberoforders-grid').click(function() {
                        var grid = $('#best-customers-numberoforders-grid').data('kendoGrid');
                        grid.dataSource.page(1); //new search. Set page size to 1
                        //grid.dataSource.read(); we already loaded the grid above using "page" function
                        return false;
                    });
                });
            </script>
        </div>
    </div>
</div>